package service.configuration.xstream.converter;

import service.configuration.xstream.TreeAssociationQueryConfig;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;


public class TreeQueryConverter implements Converter {

		@Override
		@SuppressWarnings("rawtypes")
		public boolean canConvert(Class clazz) {
			return clazz.equals(TreeAssociationQueryConfig.class);
		}

		@Override
		public void marshal(Object o, HierarchicalStreamWriter h,
				MarshallingContext m) {
		}

		@Override
		public Object unmarshal(HierarchicalStreamReader reader,
				UnmarshallingContext context) {
			TreeAssociationQueryConfig o = new TreeAssociationQueryConfig();
			o.setTo(reader.getAttribute("to"));
			o.setQuery(reader.getValue());
			return o;
		}

	}
